require('dotenv').config();
const express = require("express");
const cors = require('cors');
const bodyParser = require("body-parser");
const imgRoute = require("./src/routes/upload");
const imgSaveRoute = require("./src/routes/imgSave")
const fileUrl = require("./src/tools/file");
const { mkdir } = require("./src/tools");
const app = express();


app.set('trust proxy',true)
//解析 URL 编码的请求体
app.use(bodyParser.urlencoded({ limit: "5000mb" }));
//解析 JSON 格式的请求体数据
app.use(bodyParser.json({ limit: "5000mb", extended: true }));
//跨域设置
app.use(cors());



const img_savePath = fileUrl.imgStaticPath
mkdir(img_savePath)
app.use("/uploads",express.static(img_savePath));


//上传图片中间件
app.use("/api/upload", imgRoute);
//图片保存到本机
app.use("/api/imgSaveAs", imgSaveRoute);


app.listen(process.env.PORT || 5009, () => {
  console.log("img server listening on ",process.env.PORT || 5009);
});